﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Quanlytruongtruongtieuhoc
{
    public partial class frmCapnhatphanconggd : Form
    {
        string mon = frmPhanconggiaovien.mamon;
        string lop = frmPhanconggiaovien.malop;
        string nam = frmPhanconggvchunhiem.layNam();
        public frmCapnhatphanconggd()
        {
            InitializeComponent();
        }

        private void frmCapnhatphanconggd_Load(object sender, EventArgs e)
        {
            try
            {
                SqlDataAdapter ap = new SqlDataAdapter("select ho+' '+ten as ten_gv,ma_gv from giao_vien a,mon_hoc b where a.ma_lv=b.ma_lv and b.ma_mon='" + mon + "'", clsKetnoi.con);
                DataTable gv = new DataTable();
                gv.Clear();
                ap.Fill(gv);
                cbTengv.DataSource=gv;
                cbTengv.DisplayMember="ten_gv";
                cbTengv.ValueMember="ma_gv";

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btOk_Click(object sender, EventArgs e)
        {
            try
            {
                SqlCommand com = new SqlCommand("update giang_day set ma_gv='" + cbTengv.SelectedValue.ToString() + "' where ma_mon='" + mon + "' and ma_khoi='" + lop.Substring(0, 1) + "' and ma_lop='" + lop.Substring(2, 1) + "' and nam_hoc='" + nam + "'", clsKetnoi.con);
                DialogResult kq = new DialogResult();
                kq = MessageBox.Show("Có chắc sửa không ?", "Thông tin", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (kq == DialogResult.OK)
                {
                    com.ExecuteNonQuery();
                    MessageBox.Show("Cập nhật thành công.", "Thông tin", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
